package com.paw.ruoyi.admin.controller.monitor;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.paw.ruoyi.admin.common.annotion.OperatorLog;
import com.paw.ruoyi.admin.common.annotion.RequiresPermissions;
import com.paw.ruoyi.admin.common.constant.BusinessType;
import com.paw.ruoyi.admin.common.annotion.SkipLogParam;
import com.paw.ruoyi.admin.common.annotion.SkipResponseLog;
import com.paw.ruoyi.admin.common.AjaxResult;
import com.paw.ruoyi.admin.common.TableDataInfo;
import com.paw.ruoyi.admin.controller.BaseController;
import com.paw.ruoyi.admin.domain.SysOperLog;
import com.paw.ruoyi.admin.service.ISysOperLogService;
import com.paw.ruoyi.admin.utils.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 操作日志记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/api/monitor/operlog")
public class SysOperlogController extends BaseController<SysOperLog> {

  @Autowired
  private ISysOperLogService operLogService;

  @RequiresPermissions("monitor:operlog:list")
  @GetMapping("/list")
  public TableDataInfo list (SysOperLog operLog) {

    IPage<SysOperLog> page = operLogService.selectOperLogPageList(getPage(), operLog);
    return getDataTable(page);
  }

  @SkipLogParam
  @SkipResponseLog
  @OperatorLog(title = "操作日志", businessType = BusinessType.EXPORT)
  @RequiresPermissions("monitor:operlog:export")
  @PostMapping("/export")
  public void export (HttpServletResponse response, SysOperLog operLog) {
    List<SysOperLog> list = operLogService.selectOperLogList(operLog);
    ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
    util.exportExcel(response, list, "操作日志");
  }

  @OperatorLog(title = "操作日志", businessType = BusinessType.DELETE)
  @RequiresPermissions("monitor:operlog:remove")
  @DeleteMapping("/{operIds}")
  public AjaxResult remove (@PathVariable Long[] operIds) {
    return toAjax(operLogService.deleteOperLogByIds(operIds));
  }

  @OperatorLog(title = "操作日志", businessType = BusinessType.CLEAN)
  @RequiresPermissions("monitor:operlog:remove")
  @DeleteMapping("/clean")
  public AjaxResult clean () {
    operLogService.cleanOperLog();
    return AjaxResult.success();
  }
}
